# !/usr/bin/env python
"""
    default
    ~~~~~~~


    :Author: swq
    :Date: 2021/07/03 20:14 
"""
import os
import sys


class DefaultConfig(object):
    ENV = 'development'
    DEBUG = True
    TESTING = False
    BASE_DIR = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(
        os.path.dirname(__file__)))))

    LOG_PATH = os.path.join(BASE_DIR, 'logs')
    py_version = '{version.major}.{version.minor}'.format(version=sys.version_info)

    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + BASE_DIR + '/' + \
                              'admin.sqlite'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ECHO = False
    SECRET_KEY = 'secret key'

    # DEBUG_TB_PANELS = [
    #     'flask_debugtoolbar_warnings.WarningsPanel'
    #     'flask_debugtoolbar.panels.versions.VersionDebugPanel',
    #     'flask_debugtoolbar.panels.timer.TimerDebugPanel',
    #     'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
    #     'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
    #     'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel',
    #     'flask_debugtoolbar.panels.template.TemplateDebugPanel',
    #     'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
    #     'flask_debugtoolbar.panels.logger.LoggingPanel',
    #     'flask_debugtoolbar.panels.route_list.RouteListDebugPanel',
    #     'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
    #     'flask_debugtoolbar_warnings.WarningsPanel'
    # ]
    DEBUG_TB_PROFILER_ENABLED = True
    DEBUG_TB_ENABLED = True

    LOG_DEFAULT_CONF = {
        'version': 1,
        'disable_existing_loggers': False,

        'formatters': {
            'standard': {
                'format': '%(asctime)s %(levelname)-7s %(name)-25s %(message)s'
            },
            'advanced': {
                'format': '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
            }
        },

        'handlers': {
            'console': {
                'level': 'NOTSET',
                'formatter': 'standard',
                'class': 'logging.StreamHandler',
            },
            'api': {
                'level': 'DEBUG',
                'formatter': 'standard',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': os.path.join(LOG_PATH, 'api.log'),
                'mode': 'a',
                'maxBytes': 10485760,  # 10MB
                'backupCount': 5,
            },

            'infolog': {
                'level': 'INFO',
                'formatter': 'standard',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': os.path.join(LOG_PATH, 'info.log'),
                'mode': 'a',
                'maxBytes': 10485760,  # 10MB
                'backupCount': 5,
            },
            'errorlog': {
                'level': 'ERROR',
                'formatter': 'standard',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': os.path.join(LOG_PATH, 'error.log'),
                'mode': 'a',
                'maxBytes': 10485760,  # 10MB
                'backupCount': 5,
            }
        },

        'loggers': {
            'flask.app': {
                'handlers': ['infolog', 'errorlog'],
                'level': 'INFO',
                'propagate': True
            },
            'api': {
                'handlers': ['console', 'api'],
                'level': 'WARNING',
                'propagate': True
            },
        }
    }


if __name__ == '__main__':
    config = DefaultConfig()
    print(config.basedir)
    print(config.py_version)
